<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="建筑名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入建筑名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="建筑详细地址" prop="address" label-width="120px">
        <el-input v-model="queryParams.address" placeholder="请输入建筑详细地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="委托单位" prop="customerId" label-width="120px">
        <el-select v-model="queryParams.customerId" placeholder="请选择委托单位" clearable>
          <el-option v-for="item in customerList" :key="item.customerId" :label="item.customerName" :value="item.customerId" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['org:building:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['org:building:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['org:building:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['org:building:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="buildingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="消防技术服务机构" align="center" prop="serviceOrgName" />
      <el-table-column label="委托单位" align="center" prop="customerName" />
      <el-table-column label="建筑名称" align="center" prop="name" />
      <el-table-column label="建筑类型" align="center" prop="buildingType" :formatter="buildingTypeFormat" />
      <el-table-column label="建筑结构" align="center" prop="buildingStructure" :formatter="buildingStructureFormat" />
      <el-table-column label="建筑详细地址" align="center" prop="address" />
      <el-table-column label="地图标点描述" align="center" prop="pointPositionDesc">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" placement="top-start">
            <div slot="content" style="width:20rem">{{ scope.row.pointPositionDesc }}</div>
            <div class="ellipsisList">{{ scope.row.pointPositionDesc }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="地上层数" align="center" prop="abovegroundNumber" />
      <el-table-column label="地下层数" align="center" prop="undergroundNumber" />
      <el-table-column label="备注" align="center" prop="remark">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" placement="top-start">
            <div slot="content" style="width:20rem">{{ scope.row.remark }}</div>
            <div class="ellipsisList">{{ scope.row.remark }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['org:building:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['org:building:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row.id)"
            v-hasPermi="['org:building:list']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-setting" @click="handleEditFloor(scope.row.id)"
            v-hasPermi="['org:building:edit']">编辑楼层</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 添加或修改建筑对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="委托单位" prop="customerId">
            <el-select v-model="form.customerId" placeholder="请选择委托单位" style="width: 100%">
              <el-option v-for="item in userList" :key="item.userId" :label="item.nickName"
                :value="item.userId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建筑名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入建筑名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建筑类型" prop="buildingType">
            <el-select v-model="form.buildingType" placeholder="请选择建筑类型" style="width: 100%">
              <el-option
                v-for="item in buildTypeList"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建筑结构" prop="buildingStructure">
            <el-select v-model="form.buildingStructure" placeholder="请选择建筑结构" style="width: 100%">
              <el-option
                v-for="item in buildStructureList"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="耐火等级" prop="fireResistanceLevel">
            <el-select v-model="form.fireResistanceLevel" placeholder="请选择耐火等级" style="width: 100%">
              <el-option
                v-for="(item, index) in fireLevelList"
                :key="index"
                :label="item.value"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="危险等级" prop="hazardLevel">
            <el-select v-model="form.hazardLevel" placeholder="请选择危险等级" style="width: 100%">
              <el-option
                v-for="(item, index) in fireLevelList"
                :key="index"
                :label="item.value"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="消控室" prop="fireControlRoom">
            <el-radio-group v-model="form.fireControlRoom">
              <el-radio
                v-for="item in controlRoomList"
                :key="item.value"
                :label="item.value">
                {{item.label}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建筑详细地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入建筑详细地址" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地图标点描述" prop="pointPositionDesc">
            <el-input v-model="form.pointPositionDesc" placeholder="请输入地图标点的中文描述" @focus="changeOpenState" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地上层数" prop="abovegroundNumber">
            <el-input v-model="form.abovegroundNumber" placeholder="请输入地上层数" type="number" @input="onInput1" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地下层数" prop="undergroundNumber">
            <el-input v-model="form.undergroundNumber" placeholder="请输入地下层数" type="number" @input="onInput2" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建筑面积" prop="area">
            <el-input v-model="form.area" placeholder="请输入建筑面积" type="number" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="建筑高度" prop="height">
            <el-input v-model="form.height" placeholder="请输入建筑高度" type="number" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="使用性质" prop="natureOfUse">
            <el-input v-model="form.natureOfUse" placeholder="请输入使用性质" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" maxlength="500" />
          </el-form-item>
        </el-col>
      </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="openMap" width="80%" append-to-body :close-on-click-modal="false"
      :close-on-press-escape="false" :show-close="false">
      <div class="mapSty">
        <div class="inMapSty">
          <span style="width: 5rem;">当前位置:</span>
          <el-input type="text" v-model="mapText" id="searchInput" @input="placeAutoInput('searchInput')"
            @keyup.delete.native="deletePlace('searchInput')" />
        </div>
        <!--地址模糊搜索子组件-->
        <place-search class="place-wrap" ref="placeSearch" v-if="resultVisible" :result="result" :left="offsetLeft"
          :top="offsetTop" :width="inputWidth" :height="inputHeight" @getLocation="getPlaceLocation"></place-search>
        <div>
          <div id="allMap" class="allMap"></div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <div style="display: flex;justify-content: space-between;">
          <div v-if="formattedAddress">当前定位: <i class="el-icon-location-outline"></i>{{ formattedAddress }}</div>
          <div style="flex: 1;">
            <el-button @click="openMap = false">取 消</el-button>
            <el-button type="primary" @click="updateMapAddress">确 定</el-button>
          </div>
        </div>
      </span>
    </el-dialog>

    <Detail v-if="detailVisible" ref="Detail" @refresh="detailVisible = false" />
    <editFloorList v-if="editFloorVisible" ref="DetailFloor" @refresh="editFloorVisible = false" />
  </div>
</template>

<script>
import {
  listBuilding,
  getBuilding,
  delBuilding,
  addBuilding,
  updateBuilding,
  getCustomerMap,
  getUserManagerList
} from "@/api/system/building";

import { getDicts } from "@/api/system/dict/data";
import Detail from "./detail.vue";
import editFloorList from "./editFloor.vue";
import placeSearch from '@/components/PlaceSearch'
export default {
  name: "Building",
  components: { Detail, editFloorList, 'place-search': placeSearch },
  mounted() {
    // document添加onclick监听，点击时隐藏地址下拉浮窗
    document.addEventListener("click", this.hidePlaces, false);
    // window添加onresize监听，当改变窗口大小时同时修改地址下拉浮窗的位置
    window.addEventListener("resize", this.changePos, false)
  },
  beforeDestroy() {
    document.removeEventListener("click", this.hidePlaces, false);
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 委托单位列表
      userList: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 建筑表格数据
      buildingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 详情页面
      detailVisible: false,
      // 编辑楼层
      editFloorVisible: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        address: null,
        customerId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        customerId: [
          { required: true, message: "委托单位不能为空", trigger: "blur" },
        ],
        name: [
          { required: true, message: "请输入建筑名称", trigger: "blur" },
        ],
        buildingType: [
          { required: true, message: "请选择建筑类型", trigger: "blur" },
        ],
        buildingStructure: [
          { required: true, message: "请选择建筑结构", trigger: "blur" },
        ],
        fireResistanceLevel: [
          { required: true, message: "请选择消防等级", trigger: "blur" },
        ],
        hazardLevel: [
          { required: true, message: "请选择危险源等级", trigger: "blur" },
        ],
        fireControlRoom: [
          { required: true, message: "请选择消控室", trigger: "blur" },
        ],
        address: [
          { required: true, message: "请输入建筑详细地址", trigger: "blur" },
        ],
        pointPositionDesc: [
          { required: true, message: "请输入建筑标点描述", trigger: ['blur', 'change'] },
        ],
        abovegroundNumber: [
          { required: true, message: "请输入地上层数", trigger: "blur" },
        ],
        undergroundNumber: [
          { required: true, message: "请输入地下层数", trigger: "blur" },
        ],
        area: [
          { required: true, message: "请输入面积", trigger: "blur" },
        ]
      },
      // 高德
      openMap: false,
      inputId: '', // 地址搜索input对应的id
      result: [], // 地址搜索结果
      resultVisible: false, // 地址搜索结果显示标识
      inputWidth: 0, // 搜索框宽度
      inputHeight: 0, // 搜索框高度
      offsetLeft: 0, // 搜索框的左偏移值
      offsetTop: 0, // 搜索框的上偏移值
      sNameMap: null,  // 上车地点地图选址
      sNameMapShow: false,  // 上车地点地图选址显示
      mapText: "",
      formattedAddress: '',
      longitude: 104.065837,
      latitude: 30.657349,
      customerList: [], // 客户列表
      buildTypeList: [], // 建筑类型列表
      buildStructureList:[] , // 建筑结构列表
      controlRoomList: [
        // 消控室
        { value: '0', label: '无' },
        { value: '1', label: '有' },
      ],
      fireLevelList: [
        // 耐火等级/危险等级
        { value: '1级' },
        { value: '2级' },
        { value: '3级' },
        { value: '4级' },
      ],
    };
  },
  created() {
    this.getBuildingTypes();
    this.getBuildStructures();
    this.getCustomerList();
    this.getList();
  },
  mounted() {
    // this.initMap();
  },
  methods: {
    /** 查询建筑列表 */
    getList() {
      this.loading = true;
      // 获取用户列表
      getUserManagerList('02').then((res) => {
        this.userList = res.data;
      });
      listBuilding(this.queryParams).then((response) => {
        this.buildingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取建筑类型列表
    getBuildingTypes() {
      getDicts('sys_building_class').then(res => {
        this.buildTypeList = res.data
      })
    },
    // 获取建筑结构列表
    getBuildStructures() {
      getDicts('sys_buding_structure').then(res => {
        this.buildStructureList = res.data
      })
    },
    // 获取客户列表
    getCustomerList() {
      getCustomerMap().then(res=> {
        this.customerList = res.data
      })
    },
    // 格式化建筑类型
    buildingTypeFormat(row) {
      const type = this.buildTypeList.find(i => i.dictValue == row.buildingType)?.dictLabel
      return type
    },
    // 格式化建筑结构
    buildingStructureFormat(row) {
      const structure = this.buildStructureList.find(i => i.dictValue == row.buildingStructure)?.dictLabel
      return structure
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serviceOrgId: null,
        customerId: null,
        name: null,
        address: null,
        pointPositionDesc: null,
        abovegroundNumber: null,
        undergroundNumber: null,
        longitude: null,
        latitude: null,
        invalid: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 跳转详情
    handleDetail(id) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.Detail.init(id);
      });
    },
    // 编辑楼层
    handleEditFloor(id) {
      this.editFloorVisible = true;
      this.$nextTick(() => {
        this.$refs.DetailFloor.init(id);
      });
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加建筑";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBuilding(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改建筑";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBuilding(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBuilding(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除建筑编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBuilding(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/manager/building/export",
        {
          ...this.queryParams,
        },
        `building_${new Date().getTime()}.xlsx`
      );
    },
    // 展开地图
    changeOpenState(event) {
      this.openMap = true;
      if (this.form.longitude) {
        this.longitude = this.form.longitude;
        this.latitude = this.form.latitude;
        this.formattedAddress = this.form.pointPositionDesc
      }
      this.$nextTick(() => {
        this.initMap()
      });
    },
    // 输入框为整数
    onInput1(value) {
      // 过滤掉非数字字符
      this.form.abovegroundNumber = value.replace(/[^\d]/g, "");
      // 如果输入的是负号，则保留负号
      if (this.form.abovegroundNumber === "-") {
        this.form.abovegroundNumber = "";
      }
      // 如果输入的是小数点，则去除
      if (this.form.abovegroundNumber.includes(".")) {
        this.form.abovegroundNumber = this.form.abovegroundNumber.substring(
          0,
          this.form.abovegroundNumber.indexOf(".")
        );
      }
      // 将值转换为整数
      this.form.abovegroundNumber = parseInt(this.form.abovegroundNumber, 10);
    },
    onInput2(value) {
      // 过滤掉非数字字符
      this.form.undergroundNumber = value.replace(/[^\d]/g, "");
      // 如果输入的是负号，则保留负号
      if (this.form.undergroundNumber === "-") {
        this.form.undergroundNumber = "";
      }
      // 如果输入的是小数点，则去除
      if (this.form.undergroundNumber.includes(".")) {
        this.form.undergroundNumber = this.form.undergroundNumber.substring(
          0,
          this.form.undergroundNumber.indexOf(".")
        );
      }
      // 将值转换为整数
      this.form.undergroundNumber = parseInt(this.form.undergroundNumber, 10);
    },

    initMap() {
      this.sNameMap = new AMap.Map('allMap', {
        zoom: 16,
        scrollWheel: false,
        center: [this.longitude, this.latitude]
      });
      AMapUI.loadUI(['misc/PositionPicker'], (PositionPicker) => {
        let positionPicker = new PositionPicker({
          mode: 'dragMap',
          map: this.sNameMap
        });
        positionPicker.start();
        this.sNameMap.addControl(new AMap.ToolBar({
          liteStyle: true
        }));
      });
      this.sNameMap.on("click", this.clickMapHandler);
    },
    placeAutoInput(inputId) {
      let currentDom = document.getElementById(inputId);// 获取input对象
      let keywords = currentDom.value;
      if (keywords.trim().length === 0) {
        this.resultVisible = false;
      }
      AMap.plugin('AMap.Autocomplete', () => {
        // 实例化Autocomplete
        let autoOptions = {
          city: '全国'
        };
        let autoComplete = new AMap.Autocomplete(autoOptions); // 初始化autocomplete
        // 开始搜索
        autoComplete.search(keywords, (status, result) => {
          // 搜索成功时，result即是对应的匹配数据
          if (result.info === 'OK') {
            let sizeObj = currentDom.getBoundingClientRect(); // 取得元素距离窗口的绝对位置
            this.inputWidth = currentDom.clientWidth;// input的宽度
            this.inputHeight = currentDom.clientHeight + 2;// input的高度，2是上下border的宽
            // input元素相对于页面的绝对位置 = 元素相对于窗口的绝对位置
            this.offsetTop = sizeObj.top + this.inputHeight; // 距顶部
            // this.offsetTop = 36; // 距顶部
            this.offsetLeft = sizeObj.left; // 距左侧
            this.result = result.tips;
            this.inputId = inputId;
            this.resultVisible = true;
          }
        })
      })
    },
    // 点击地图选点
    clickMapHandler(e) {
      this.pickAddress('searchInput', e.lnglat.lng, e.lnglat.lat)
    },
    // 隐藏搜索地址下拉框
    hidePlaces(event) {
      let target = event.target;
      // 排除点击地址搜索下拉框
      if (target.classList.contains("address")) {
        return;
      }
      this.resultVisible = false;
    },
    // 修改搜索地址下拉框的位置
    changePos() {
      if (this.inputId && this.$refs['placeSearch']) {
        let currentDom = document.getElementById(this.inputId);
        let sizeObj = currentDom.getBoundingClientRect(); // 取得元素距离窗口的绝对位置
        // 元素相对于页面的绝对位置 = 元素相对于窗口的绝对位置
        let inputWidth = currentDom.clientWidth;// input的宽度
        let inputHeight = currentDom.clientHeight + 2;// input的高度，2是上下border的宽
        let offsetTop = sizeObj.top + inputHeight; // 距顶部
        let offsetLeft = sizeObj.left; // 距左侧
        this.$refs['placeSearch'].changePost(offsetLeft, offsetTop, inputWidth, inputHeight);
      }
    },
    // 获取子组件返回的位置信息
    getPlaceLocation(item) {
      if (item) {
        this.resultVisible = false;
        if (item.location && item.location.getLat()) {
          this.pickAddress(this.inputId, item.location.getLng(), item.location.getLat());
        } else {
          this.geocoder(item.name, this.inputId);
        }
      }
    },
    // 地图选址
    pickAddress(inputId, lon, lat) {
      this.sNameMap = new AMap.Map('allMap', {
        zoom: 16,
        scrollWheel: false,
        center: [lon, lat]
      });
      this.sNameMap.on("click", this.clickMapHandler);
      if (inputId === "searchInput") {
        this.sNameMapShow = true;
        AMapUI.loadUI(['misc/PositionPicker'], (PositionPicker) => {
          let positionPicker = new PositionPicker({
            mode: 'dragMap',
            map: this.sNameMap
          });
          positionPicker.on('success', (positionResult) => {
            this.form.latitude = positionResult.position.lat;
            this.form.longitude = positionResult.position.lng;
            this.formattedAddress = positionResult.address;
            this.mapText = positionResult.address
          });
          positionPicker.on('fail', (positionResult) => {
            this.$message.error("地址选取失败");
          });
          positionPicker.start();
          this.sNameMap.addControl(new AMap.ToolBar({
            liteStyle: true
          }));
        });
      }
    },
    // 地理编码
    geocoder(keyword, inputValue) {
      let geocoder = new AMap.Geocoder({
        radius: 1000 //范围，默认：500
      });
      //地理编码,返回地理编码结果
      geocoder.getLocation(keyword, (status, result) => {
        if (status === 'complete' && result.info === 'OK') {
          let geocode = result.geocodes;
          if (geocode && geocode.length > 0) {
            if (inputValue === "sname") {
              this.form.latitude = geocode[0].location.getLat();
              this.form.longitude = geocode[0].location.getLng();
              this.formattedAddress = keyword;
              // 如果地理编码返回的粗略经纬度数据不需要在地图上显示，就不需要调用地图选址，且要隐藏地图
              // this.pickAddress("sname", geocode[0].location.getLng(), geocode[0].location.getLat());
              this.sNameMapShow = false;
            }
          }
        }
      });
    },
    // 做删除操作时还原经纬度并验证字段
    deletePlace(inputId) {
      if (inputId === "searchInput") {
        this.longitude = 104.065837;
        this.latitude = 30.657349;
      }
    },
    // 改变地图地址
    updateMapAddress() {
      this.form.pointPositionDesc = this.formattedAddress;
      this.openMap = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.ellipsisList {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  /* 控制最多显示3行文字 */
  overflow: hidden;
  text-overflow: ellipsis;
}

.mapSty {
  width: 100%;
  height: 450px;
  position: relative;
}

#allMap {
  width: 100%;
  height: 450px;
}

.map-wrapper .map-self {
  height: 150px;
  width: 300px;
}

#panel {
  position: absolute;
  background-color: white;
  max-height: 90%;
  overflow-y: auto;
  top: 36px;
  right: 0;
  width: 280px;
}

.inMapSty {
  width: 20rem;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 999999;
  opacity: 0.8;
  display: flex;
  height: 36px;
  line-height: 36px;

}
</style>